<template>
	<view class="content">
		<view v-if="list.length">
			<view @click="detail(item)" class="item" v-for="item in list">
				<view class="left">
					<view class="name">
						{{item.name || ''}}
					</view>
					<view class="part">
						机构名称
					</view>
					<view class="time">
						
						<!--  -->
						{{  item.time}}
					</view>
				</view>
				<view class="right">查看
			
					<image class="icon" src="../../static/you-magic/images/more.png"></image>
				</view>
			</view>
		</view>
		<view v-else class="empty">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>

// import dayjs from 'dayjs'
	export default {
		data() {
			return {
				// 分页
				page: 0,
				limit: 10,
				status: "loadmore",
				searDate: false,
				list: [],
				total: 0,
				//判断是否发送请求的条件
				load: false,
				// 分页
			}
		},

		onLoad() {
			this.getList();
		},
		onReachBottom() {
			//页面抵达底部后，如果此时的status状态是加载更多，那就调用loadmore方法
			if (this.status === "loadmore") {
				this.loadmore();
			}
		},
		onPullDownRefresh() {
			//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
			this.page = 1;
			this.list = [];
			this.keywords = ''
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh(); //停止下拉刷新动画
			}, 1000);
		},
		methods: {
			detail(item){
				uni.navigateTo({
					url: "/pages/scan/detail?id="+item.id
				})
			},

		loadmore() {
			// 每次出发该方法，都要使页数加一
			this.page++;
			// 页数加一后，在调用getList方法，获取下一页的数据
			this.getList();
		},
		getList() {
			this.searDate = false;

			// 判断当前是否在请求，如果为true正在请求数据，就让他返回空，如果为false没在请求，就让它开始请求数据
			if (this.load) {
				return;
			}
			this.load = true;
			// 请求数据时，状态改为加载中状态
			this.status = "loading";

			this.$u.api
				.eventhistory({
					size: this.limit,
					page: this.page,
				})
				.then((res) => {
					this.searDate = true;

					// 请求完以后，将load改为false，方便下一次发送请求
					this.load = false;
					// 判断获取的数据是否正确，当res.code=0时，数据正确
					if (res.length) {
						// 当获取到的数据不正确时，给用户错误提示信息
						return uni.showToast({
							title: res.msg,
							icon: "none",
						});
						this.status = "nomore";
					}

					// 如果从接口中获取到的数据是正确的，获取到数据的总条数
					this.total = res.total;
					// 将获取到的数据给数据列表，此处是解构，不适合用push
					this.list = [...this.list, ...res.rows];
					
					this.list.map(r=>{
						r.time = this.getDate(r.created_at)
						console.log(r.time,5555);
						r.name = JSON.parse(r.event_result_data)?.product_organization
					})
					this.ismore();
				});
		},
		
		getDate(val) {
		
			let now  =new Date(val)
		      let year = now.getFullYear() // 得到年份
		      let month = now.getMonth() // 得到月份
		      let date = now.getDate() // 得到日期
		      month = month + 1
		      month = month.toString().padStart(2, '0')
		      date = date.toString().padStart(2, '0')
		      let defaultDate = `${year}-${month}-${date}`
		      return defaultDate
		    },

		ismore() {
			if (this.total === this.list.length) {
				this.status = "nomore";
			} else {
				this.status = "loadmore";
			}
		},
		}


	}
</script>
<style>
	page {
		background: #f4f4f4;
	}
</style>
<style scoped lang="scss">
	.empty{
		padding: 100px 0;
	}
	.content {
		.item {
			background: url('https://file.roumeiji.com/img/11.png') no-repeat;
			background-size: cover;
			margin: 16rpx auto 0;
			width: 698rpx;
			height: 160rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 25rpx 61rpx;

			.left {
				flex: 1;

				.name {

					height: 27rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #1A1A1A;
					line-height: 1;
					display: -webkit-box;
					word-break: break-all;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: pre-line;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
				}

				.part {

					height: 20rpx;
					font-size: 21rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #808080;
					line-height: 1;
					margin: 13rpx 0 33rpx 0;
					display: -webkit-box;
					word-break: break-all;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: pre-line;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;

				}

				.time {
					height: 15rpx;
					font-size: 19rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #808080;
					line-height: 1;
				}
			}

			.right {
				margin-left: 20px;
				display: flex;
				align-items: center;
				justify-content: center;

				height: 22rpx;
				font-size: 23rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #808080;

				.icon {
					width: 12rpx;

					height: 22rpx;
					margin: 0 0 0 25rpx;
				}
			}
		}
	}
</style>
